﻿$(function () {
    var screenwidth, screenheight, mytop, getPosLeft, getPosTop
    screenwidth = $(window).width();
    screenheight = $(window).height();
    //获取滚动条距顶部的偏移
    mytop = $(document).scrollTop();
    //计算弹出层的left
    getPosLeft = screenwidth / 2 - 340;
    //计算弹出层的top
    getPosTop = screenheight / 2 - 150;
    //css定位弹出层
    $("div.popupWindow").css({ "left": getPosLeft, "top": getPosTop });
    $("div.batchWindow").css({ "left": getPosLeft, "top": getPosTop });
    //当浏览器窗口大小改变时
    $(window).resize(function () {
        screenwidth = $(window).width();
        screenheight = $(window).height();
        mytop = $(document).scrollTop();
        getPosLeft = screenwidth / 2 - 340;
        getPosTop = screenheight / 2 - 150;
        $("div.popupWindow").css({ "left": getPosLeft, "top": getPosTop + mytop });
        $("div.batchWindow").css({ "left": getPosLeft, "top": getPosTop + mytop });
    });
    //当拉动滚动条时，弹出层跟着移动
    $(window).scroll(function () {
        screenwidth = $(window).width();
        screenheight = $(window).height();
        mytop = $(document).scrollTop();
        getPosLeft = screenwidth / 2 - 340;
        getPosTop = screenheight / 2 - 150;
        $("div.popupWindow").css({ "left": getPosLeft, "top": getPosTop + mytop });
        $("div.batchWindow").css({ "left": getPosLeft, "top": getPosTop + mytop });
    });

    //点击关闭弹出窗口
    $("p.closePopup").click(function () {
        $("div.popupWindow").hide();
        $("div.batchWindow").hide();
        $("#greybackground").hide();
        return false;
    });
    //checkbox事件
    $("input[type='checkbox']#cbkAll").click(function () {
        if (this.checked) {
            $("input[type='checkbox']", $("#tblMain")).attr("checked", "checked");
        } else {
            $("input[type='checkbox']", $("#tblMain")).removeAttr("checked");
        }
    });
    //checkbox事件
    $("input[type='checkbox']", $("#tblMain tr td")).click(function () {
        if ($("input[type='checkbox']", $("#tblMain tr td")).length == $("input[type='checkbox']:checked", $("#tblMain tr td")).length) {
            $("input[type='checkbox']#cbkAll").attr("checked", "checked");
        } else {
            $("input[type='checkbox']#cbkAll").removeAttr("checked");
        }
    });
});